package com.huang;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author HuangShen
 * @Description 动态代理类
 * @create 2021-03-29 14:57
 */
public class ProxyFactory {


    public static Object getProxyInstance(Object obj){
         InvocationHandler invocationHandler = new MyInvocationHandler(obj);
         return  Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(),invocationHandler);
    }

}

class MyInvocationHandler implements InvocationHandler{
     private Object obj;

     public  MyInvocationHandler(Object obj){
        this.obj=obj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        Object invoke = method.invoke(obj, args);


        return invoke;
    }
}
